package com.mmy.dao.scenic;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.scenic.TScenicOrder;

public interface TScenicOrderRepository extends JpaRepository<TScenicOrder, Integer> {
	/**
	 * 根据订单id查找
	 *
	 * @author 创建人 hanxl 整理
	 * @date 创建日期 2020.10.29
	 */
	@Query(value = "select *  from tScenicOrder where iID = :iID", nativeQuery = true)
	TScenicOrder findByID(@Param("iID") int iID);

	/**
	 * 获取最大流水号
	 * 
	 * @return 返回值说明 流水号
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.10.29
	 */
	@Query(value = "SELECT MAX(iID)  FROM tScenicOrder", nativeQuery = true)
	Object getMaxID();

	/**
	 * 获得订单最大编码
	 *
	 * @author 创建人dingxd
	 * @date 修改日期 2020.11.17
	 */
	@Query(value = "SELECT MAX(cOrderID) FROM tScenicOrder WHERE LEFT(cOrderID,16) = CONCAT(:iPlanID,REPLACE(DATE(NOW()),'-',''))", nativeQuery = true)
	Object getMaxCode(@Param("iPlanID") String strPlanID);

	/**
	 * 新建订单
	 *
	 * @author 创建人hanxl
	 * @date 修改日期 2021.01.20
	 */

	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tScenicOrder "
			+ "(iID, cOrderID, iReserveUserID, dReserveDate, cReserveName, cReserveTel, iOrderUserID, dOrderDate, cOrderName, cOrderTel, cIdentity, iOrderState, fOrderAmount, iOrderNumber, dUseDate, fReceivable, fReceipt, fFloor, fPeer, fPrice, iPayType, cVoucher, iCashierState, dCashierDate, iCashierID, iAccountState, dAccountDate, iAccountID, iInvoiceState, fRefund, iRefundState, iRefundProcess, bRemittanceState, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES "
			+ "(:iID, NULL,  0,  NULL,  NULL,  NULL,  0,  NULL,  NULL,  NULL,  NULL, 0, 0, 0,  NULL, 0, 0, 0, 0, 0, 0,  NULL, 0,  NULL,  0, 0,  NULL,  0, 0,  NULL, 0, 0, 0,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL)", nativeQuery = true)
	void save(@Param("iID") int id);

	/*
	 * 根据id删除
	 */
	@Transactional
	@Modifying
	@Query(value = "delete from tScenicOrder where tScenicOrder.iID in (:lstID)", nativeQuery = true)
	void delScenicOrder(@Param("lstID") List<Integer> lstID);

}
